package entity

import (
	. "data/datatype"
)

var objects = make(map[string]func() interface{})

//注册函数
func register(name string, createfunc func() interface{}) {
	if _, dup := objects[name]; dup {
		panic("entity: Register called twice for object " + name)
	}
	objects[name] = createfunc
}

//创建数据对象
func Create(name string) interface{} {
	if create, exist := objects[name]; exist {
		return create()
	}

	return nil
}

//获取类型
func GetType(name string) int {
	switch name {

	case "BaseObj":
		return NONE
	case "Npc":
		return NPC
	case "Player":
		return PLAYER
	case "BaseScene":
		return SCENE
	default:
		return 0
	}
}

//初始化函数
func init() {

	register("BaseObj", func() interface{} {
		return CreateBaseObj()
	})
	register("Npc", func() interface{} {
		return CreateNpc()
	})
	register("Player", func() interface{} {
		return CreatePlayer()
	})
	register("BaseScene", func() interface{} {
		return CreateBaseScene()
	})
}
